﻿#ifndef PST_ANIMATIONSETTINGDATA_H
#define PST_ANIMATIONSETTINGDATA_H

#include <QObject>
#include <QDomElement>
#include <QDomDocument>
#include <QDomNodeList>
#include "BaseModule/GlobalHelper.h"

namespace pst
{
    class AnimationSettingData : public QObject
    {
        Q_OBJECT
    public:
        AnimationSettingData(QObject* parent = nullptr) :QObject(parent) {}

        bool isThetaChecked() const { return m_isThetaChecked; }
        void setThetaChecked(bool checked) { m_isThetaChecked = checked; }

        bool isPhiChecked() const { return m_isPhiChecked; }
        void setPhiChecked(bool checked) { m_isPhiChecked = checked; }

        double thetaAngle() const { return m_thetaAngle; }
        void setThetaAngle(double angle) { m_thetaAngle = angle; }

        double phiAngle() const { return m_phiAngle; }
        void setPhiAngle(double angle) { m_phiAngle = angle; }

        int sampleRate() const { return m_sampleRate; }
        void setSampleRate(int rate) { m_sampleRate = rate; }

        int frameRate() const { return m_frameRate; }
        void setFrameRate(int rate) { m_frameRate = rate; }

        /// @brief 文件写出至工程文件
        QDomElement& writeToProjectFile(QDomDocument* doc, QDomElement* element, bool isdiso = false)
        {
            QDomElement _AnimationSettingDataRoot = doc->createElement("AnimationSettingData");

            GlobalHelperInstance->createDomElement(doc, &_AnimationSettingDataRoot, "IsThetaChecked", QString::number(m_isThetaChecked));
            GlobalHelperInstance->createDomElement(doc, &_AnimationSettingDataRoot, "IsPhiChecked", QString::number(m_isPhiChecked));
            GlobalHelperInstance->createDomElement(doc, &_AnimationSettingDataRoot, "ThetaAngle", QString::number(m_thetaAngle));
            GlobalHelperInstance->createDomElement(doc, &_AnimationSettingDataRoot, "PhiAngle", QString::number(m_phiAngle));
            GlobalHelperInstance->createDomElement(doc, &_AnimationSettingDataRoot, "SampleRate", QString::number(m_sampleRate));
            GlobalHelperInstance->createDomElement(doc, &_AnimationSettingDataRoot, "FrameRate", QString::number(m_frameRate));

            element->appendChild(_AnimationSettingDataRoot);

            return _AnimationSettingDataRoot;

        }
        /// @brief 从工程文件读入数据
        void readFromProjectFile(QDomElement* element, bool isdiso = false)
        {
            m_isThetaChecked = (bool)element->elementsByTagName("IsThetaChecked").at(0).toElement().text().toInt();
            m_isPhiChecked = (bool)element->elementsByTagName("IsPhiChecked").at(0).toElement().text().toInt();
            m_thetaAngle = (double)element->elementsByTagName("ThetaAngle").at(0).toElement().text().toDouble();
            m_phiAngle = (double)element->elementsByTagName("PhiAngle").at(0).toElement().text().toDouble();
            m_sampleRate = (int)element->elementsByTagName("SampleRate").at(0).toElement().text().toInt();
            m_frameRate = (int)element->elementsByTagName("FrameRate").at(0).toElement().text().toInt();
        }

    private:
        bool m_isThetaChecked{ true };
        bool m_isPhiChecked{ false };
        double m_thetaAngle{ 15. };
        double m_phiAngle{ 15. };
        int m_sampleRate{ 1 };
        int m_frameRate{ 3 };
    };
}
#endif
